package com.yumei.trader.gym.client;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;

import java.io.Serializable;

public class BasePage extends AppCompatActivity {


    protected ImmersionBar mImmersionBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        ActivityController.addActivity(this);

    }




    /**
     * 设置标题栏透明
     */
    protected void transparentBar(){

        mImmersionBar = ImmersionBar.with(this);
        mImmersionBar.transparentBar().hideBar(BarHide.FLAG_HIDE_STATUS_BAR)
                .hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR).init();   //所有子类都将继承这些相同的属性
    }

    public ImmersionBar getImmersionBar(){
        return mImmersionBar;
    }

    public void initImmersionBar(View statusView) {
        if (ImmersionBar.isSupportStatusBarDarkFont())
            getImmersionBar().statusBarDarkFont(true, 0.2f)
                    .statusBarView(statusView)
                    .init();
    }


    /**
     * 隐藏虚拟按键，并且全屏
     */
    public  void hideBottomNav(Activity activity) {
        /*
        View decorView = activity.getWindow().getDecorView();
        decorView.setSystemUiVisibility(View.VISIBLE);
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
         */
    }

    protected void showToast(String msg) {

        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }



    protected void startActivity(Class<?> cls) {

        super.startActivity(new Intent(this, cls));
    }


    protected  void startActivity(Class<?> cls, String name, Serializable obj){
        Intent intent = new Intent(this,cls);
        intent.putExtra(name,obj);
        super.startActivity(intent);
    }


    protected void startActivityForResult(Class<?> cls, int requestCode) {

        super.startActivityForResult(new Intent(this, cls), requestCode);
    }


    protected void startActivityForResult(Class<?> cls, String name,Serializable obj,int requestCode) {

        Intent intent = new Intent(this,cls);
        intent.putExtra(name,obj);

        super.startActivityForResult(intent, requestCode);
    }


    protected void onBackAction(){

        finish();
    }


    protected void onBackAction(int resultCode){
        this.setResult(resultCode);
        finish();
    }

    protected void onBackAction(int resultCode,Intent intent){
        this.setResult(resultCode,intent);
        finish();
    }


    protected View inflate(int resId) {

        return LayoutInflater.from(this).inflate(resId, null);
    }


    public void onDestroy(){
        super.onDestroy();

        ActivityController.removeActivity(this);
    }
}
